package com.example.user.mvp.presenter;

import android.util.Log;
import android.widget.Toast;
import com.example.lib_core.http.BaseObserver;
import com.example.lib_core.init.Core;
import com.example.lib_core.mvp.presenter.BasePresenter;
import com.example.user.app.MyApplication;
import com.example.user.bean.UserEntity;
import com.example.user.mvp.contract.LoginContract;

public class LoginPresenter extends BasePresenter<LoginContract.Model, LoginContract.View> {
    public LoginPresenter(LoginContract.Model mModel, LoginContract.View mView) {
        super(mModel, mView);
    }
    public void login(){
        Log.i("TAG", "login: ==============================");
        if (mView.getUserName().length() == 0) {
            Toast.makeText(Core.getInstance().getApplication(), "请输入用户名", Toast.LENGTH_SHORT).show();
            return;
        }
        if (mView.getUserPwd().length() == 0) {
            Toast.makeText(Core.getInstance().getApplication(), "请输入密码", Toast.LENGTH_SHORT).show();
            return;
        }
        mModel.requestLogin(mView.getUserName(), mView.getUserPwd(), new BaseObserver<UserEntity>() {
            @Override
            public void success(UserEntity bean) {
                mView.loginOk();
            }
        });
    }
}
